<html>
<head><meta charset="utf-8"><title>references to fn pointers changed from stable to beta · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html">references to fn pointers changed from stable to beta</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178300612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178300612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178300612">(Oct 16 2019 at 15:33)</a>:</h4>
<p><a href="https://stackoverflow.com/q/58416511/155423" target="_blank" title="https://stackoverflow.com/q/58416511/155423">Casting a function reference producing an invalid pointer?</a></p>



<a name="178300677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178300677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178300677">(Oct 16 2019 at 15:34)</a>:</h4>
<blockquote>
<p>Ran on stable 1.38.0 this prints the function pointer, but beta (1.39.0-beta.6) and nightly return '1'. </p>
</blockquote>
<p>Is this a bug / regression? Is it related to const eval stuff at all?</p>
<p>/cc <span class="user-mention" data-user-id="124288">@oli</span></p>



<a name="178302079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178302079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178302079">(Oct 16 2019 at 15:49)</a>:</h4>
<p>The MIR doesn't appear to have changed. Perhaps it's related the the recent-ish LLVM upgrade?</p>



<a name="178302399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178302399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178302399">(Oct 16 2019 at 15:53)</a>:</h4>
<p>Looking at the MIR, the type of <code>ptr</code> is unchanged; for both <code>stable</code> and <code>beta</code> it is:</p>
<div class="codehilite"><pre><span></span>    let _1: *const unsafe fn() {foo};    // &quot;ptr&quot; in scope 0 at src/main.rs:6:9: 6:12
</pre></div>



<a name="178309490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309490">(Oct 16 2019 at 17:20)</a>:</h4>
<p>that code is weird though. <code>&amp;foo</code> is not a fn ptr but a ref-to-fn-ptr...</p>



<a name="178309560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309560">(Oct 16 2019 at 17:21)</a>:</h4>
<p>probably <code>&amp;foo</code> now infers to a ref-to-the-unnamble-ZST-representing-<code>foo</code></p>



<a name="178309568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309568">(Oct 16 2019 at 17:21)</a>:</h4>
<p>which would explain the <code>1</code></p>



<a name="178309600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309600">(Oct 16 2019 at 17:21)</a>:</h4>
<p>you see, for every function in Rust there exists a correpsonding type. that type has no run-time information so its size is 0.</p>



<a name="178309615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309615">(Oct 16 2019 at 17:21)</a>:</h4>
<p>the expression <code>foo</code> has that type</p>



<a name="178309673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309673">(Oct 16 2019 at 17:22)</a>:</h4>
<p>but that unnamable ZST coerces to <code>fn()</code> which is what happens when people create fn ptrs</p>



<a name="178309742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309742">(Oct 16 2019 at 17:23)</a>:</h4>
<p>but here maybe the coercion doesnt trigger anymore for... reasons. so now instead of a reference to a fn ptr, you now get a reference to the ZST. and because there's no memory backing them, <code>&amp;ZST</code> just become <code>1</code> in some cases.</p>



<a name="178309843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178309843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178309843">(Oct 16 2019 at 17:24)</a>:</h4>
<p>evidence that even on stable this does <em>not</em> print <code>foo</code>'s address:<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7ba08d2b12d4caf4f95b876797907b6d" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7ba08d2b12d4caf4f95b876797907b6d">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7ba08d2b12d4caf4f95b876797907b6d</a></p>



<a name="178338063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178338063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178338063">(Oct 16 2019 at 23:56)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yeah, should have said I know all that part <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="178338079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178338079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178338079">(Oct 16 2019 at 23:56)</a>:</h4>
<p>The change / “... reasons” is the thing I’m worried about.</p>



<a name="178338121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/references%20to%20fn%20pointers%20changed%20from%20stable%20to%20beta/near/178338121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/references.20to.20fn.20pointers.20changed.20from.20stable.20to.20beta.html#178338121">(Oct 16 2019 at 23:57)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>